package com.example.controller;

import com.example.model.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.*;

@Controller
@RequestMapping("/freemarker")
public class FreeMarkerController {

    @GetMapping("/index")
    public String index() {
        System.out.println("跳转 index.ftl 首页");
        return "fm/index";
    }

    @GetMapping("/user/list")
    public String list(ModelMap modelMap) {
        List<User> userList = new ArrayList<>();
        userList.add(new User("1", "听风", 25, "北京"));
        userList.add(new User("2", "杰克", 23, "上海"));
        userList.add(new User("3", "米亚", 23, "郑州"));

        modelMap.addAttribute("userList", userList);
        return "fm/user/list";
    }

    @GetMapping("/user/map")
    public String map(ModelMap modelMap) {
        Map<String, String> appMap = new HashMap<>();
        appMap.put("A", "IT IS A");
        appMap.put("B", "IT IS B");
        appMap.put("C", "IT IS C");

        modelMap.addAttribute("appMap", appMap);
        return "fm/user/map";
    }

}
